<?php /*a:2:{s:47:"G:\project\insure\view\admin\groups\index.phtml";i:1593776064;s:39:"G:\project\insure\view\admin\base.phtml";i:1594023911;}*/ ?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>HQadmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/hqui/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="/static/hqui/module/admin.css?v=316"/>
  <link rel="stylesheet" href="/static/css/fonts.css">
  <link rel="stylesheet" href="/static/css/base.css">
  
</head>
<style>
    .layui-form-label{
        width: 100px;
    }
    .layui-input-block {
        margin-left: 130px;
        min-height: 36px
    }
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        

<div class="layui-card">
    <div class="layui-card-body">
        <div style="float: left;margin-right: 20px;margin-top: 5px">
            <input name="groups" style="width: 200px;height: 30px" id="groups" placeholder="请输入佣金组名称">
            <input name="policy" style="width: 200px;height: 30px" id="policy" placeholder="请输入政策名称">
            <input name="bill" style="width: 200px;height: 30px" id="bill" placeholder="请输入出单方名称">
        </div>

        <div class="layui-btn-group">
            <input id="addurl" value="/admin/groups/groups_add?isedit=0" hidden="hidden">
            <input id="oriaddurl" value="/admin/groups/groups_add?isedit=0" hidden="hidden">
            <button class="layui-btn search" data-type="reload">搜索</button>
            <input id="addurl" value="/admin/employee/addgroup?isedit=0" hidden="hidden">
            <input id="oriaddurl" value="/admin/employee/addgroup?isedit=0" hidden="hidden">
            <input id="editurl" value="/admin/groups/groups_add?isedit=1" hidden="hidden">
            <a class="layui-btn" data-width="830px" data-height="800px" id="add"><i class="fa fa-plus-circle"></i> 添加</a>
            <a id="delAll" class="layui-btn" data-width="830px" data-height="800px" style="margin-left: 20px"><i class="fa fa-minus-circle"></i> 删除</a>
        </div>
    </div>

    <table id="tableList0" lay-filter="tableList0"></table>

    <!-- 表格操作列 -->
    <script type="text/html" id="tableTBTrack">
        <a data-id="{{d.id}}" class="layui-btn layui-btn-sm"  lay-event="edit">编辑成员</a>
        <a id="edit" data-id="{{d.id}}" class="layui-btn layui-btn-sm" data-width="830px" data-height="800px">修改</a>
        <a href="<?php echo url('admin/groups/groups_del'); ?>?id={{d.id}}" class="layui-btn  layui-btn-sm layui-btn-danger ajax-delete">删除</a>
    </script>

    <!-- 权限列 -->
    <script type="text/html" id="sort_order">
        <input type="text" value="get_ad({{d.id}},'desc')" autocomplete="off" class="layui-input" disabled>
    </script>
</div>


    </div>
</div>

<script type="text/javascript" src="/static/hqui/libs/layui/layui.all.js"></script>
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/layui.base.js"></script>
<script type="text/javascript" src="/static/hqui/js/common.js?v=316"></script>
<script type="text/javascript">

    //工具函数 将表单里数据 序列化成json对象
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };

    function refreshArea(_formWin){
        var _formWinObj = $("#layui-layer"+_formWin);
        var w = _formWinObj.outerWidth();
        var h = _formWinObj.outerHeight();
        var l = ($(document).width()-w)/2;
        var t = ($(window).height()-h)/2;
        _formWinObj.css({
            "left":l,
            "top":t
        });
    }



    $(document).on('click',"#edit",function(){
        console.log($(this).data('id'));
        console.log($('#editurl').val() + '&id=' + $(this).data('id'));
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#editurl').val() + '&id=' + $(this).data('id'),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $('#add').click(function(){
        layer.open({
            type: 2,
            shade: false,
            area: '1000px',

            maxmin: true,
            content: $('#addurl').val(),
            zIndex: layer.zIndex, //重点1
            success: function(layero, index){
                refreshArea(index);
                var height = $(window.parent.document).height();
                layer.style(index, {
                    height: (height -230) + 'px',
                    top: '10px'
                });
            }
        });
    })

    $("#agency").change(function(){
        $('#addurl').val($('#oriaddurl').val());
        $('#editurl').val($('#oriaddurl').val());
        var href = $('#addurl').val();
        href += '&aid='+$(this).val();
        $('#addurl').val(href);

        var href1 = $('#editurl').val();
        href1 += '&aid='+$(this).val();
        $('#editurl').val(href1);
        $.ajax({
            url:'getCompany',
            data:{'id':$(this).val()},
            method:'post',
            success:function(res){
                $('#company').children().remove();
                let data = JSON.parse(res);
                let str = '<option value="">全部</option>';
                for(let i in data){
                    str += ' <option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
                }
                $('#company').append(str);
            }
        });
    });

    $('#company').change(function(){
        var href = $('#addurl').val();
        href += '&cid='+$(this).val();
        $('#addurl').val(href);

        var href1 = $('#editurl').val();
        href1 += '&cid='+$(this).val();
        $('#eidturl').val(href1);
    })

</script>


<script>
    layui.use(['layer', 'form', 'table', 'util', 'dropdown','element'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var dropdown = layui.dropdown;
        var element = layui.element;

        element.on('tab(test1)', function(){
            $('#tab').val(this.getAttribute('lay-id'));

            var href = $('#add').attr('href');
            href += '&type='+ this.getAttribute('lay-id');
            $('#add').attr('href',href);
        });

        table.on('tool(tableList0)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if(layEvent === 'edit'){ //添加
                var id = obj.data.id;

                layer.open({
                    type: 2,
                    shade: false,
                    area: $(window.parent.document).width() - 300 + 'px',

                    maxmin: true,
                    content: '/admin/groups/editEmployee?id='+id,
                    zIndex: layer.zIndex, //重点1
                    success: function(layero, index){
                        refreshArea(index);
                        var height = $(window.parent.document).height();
                        layer.style(index, {
                            height: (height -170) + 'px',
                            top: '10px'
                        });
                    }
                });
            }
        });

        // 渲染回访表格
        var insTb1 = table.render({
            elem: '#tableList0',
            url: "<?php echo url('admin/groups/groups_json?type=0'); ?>",
            page: true,
            limit:10,
            limits:[15,30,45,60,75,90],
            cellMinWidth: 100,
            size:'lg',even:true,
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {type:'numbers',title:'#'},
                {field: 'name', title: '佣金组名称'},
                {field:'pname',title:'政策名称'},
                {field:'pid',title:'政策编码'},
                {field:'city',title:'车牌地区'},
                {field:'car', title: '新旧车'},
                {field:'displacement',title:'排量划分'},
                {field: 'bname', title: '出单方'},
                {field: 'commercial_type', title: '商业险计算方式'},
                {field: 'commercial_num', title: '业务员商业险佣金'},
                {field: 'compolsury_type', title: '交强险计算方式'},
                {field: 'compolsury_num', title: '业务员交强险佣金'},
                {field: 'effect_time', title: '政策开始日期'},
                {align: 'center', toolbar: '#tableTBTrack', title: '操作', width: 150}
            ]],
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            },id: 'testReload0'
        });

        var $ = layui.$, active = {
            reload: function(){
                //执行重载
                table.reload('testReload0', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        policy :$('#policy').val(),
                        groups:$('#groups').val(),
                        bill:$('#bill').val(),
                    }
                }, 'data');
            }
        };



        $('.search').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });



    $(".editEmployee").on('click', function(){
        console.log('das');

    });

    $('#delAll').click(function(){
        var data = table.cache.testReload0;
        var ids = [];

        for(let i = 0;i<data.length;i++){
            if(data[i]['LAY_CHECKED'] == true){
                ids.push(data[i]['id']);
            }
        }

        if(ids.length == 0){
            layer.open({
                content: '请先勾选' //这里content是一个普通的String
            });
            return;
        }

        layer.confirm('确定要删除吗', {icon: 3, title:'提示'}, function(index){
            $.ajax({
                url:'groups_del',
                data:{'id':ids},
                method:'post',
                success:function(res){
                    layer.open({
                        content: res.msg //这里content是一个普通的String
                    });
                    window.location.reload()
                }
            });
        });
    });


</script>

</body>
</html>